﻿using System.Text.RegularExpressions;

namespace CMS.Class
{
    /// <summary>
    /// @Author: NamLB@vietstock.vn
    /// </summary>
    public class CHTMLParser
    {
        protected string _Content;
        public CHTMLParser(string content)
        {
            this._Content = content;
        }

        public string ParseString(string pattern)
        {
            Match match = Regex.Match(this._Content, pattern, RegexOptions.CultureInvariant| RegexOptions.IgnoreCase);
            if (match != null && match.Success)
                return Regex.Replace(System.Web.HttpUtility.HtmlDecode(match.Value), @"<[^>]*>", string.Empty, RegexOptions.IgnoreCase);
            
            return string.Empty;
        }

        public string Replace(string pattern, string strToReplace)
        {
            return Regex.Replace(this._Content, "<img src='(http|https)://.*?(/.*?)'", "<img src='/", RegexOptions.IgnoreCase);
        }
    }
}